<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="/struts-tags" prefix="s"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

<link href="${pageContext.request.contextPath}/css/header.css"
	rel="stylesheet" type="text/css" />

<link href="${pageContext.request.contextPath}/css/sub_manager.css"
	rel="stylesheet" type="text/css" />

<link href="${pageContext.request.contextPath}/css/sub_detalie_list.css"
	rel="stylesheet" type="text/css" />

<link href="${pageContext.request.contextPath}/css/sub_add_item.css"
	rel="stylesheet" type="text/css" />


<link href="${pageContext.request.contextPath}/css/common.css"
	rel="stylesheet" type="text/css" />
<script src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
<script src="${pageContext.request.contextPath}/js/cookie.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>试题添加选项页面</title>
</head>
<body onload="loadingSubDetaile()">
	<%@ include file="header.jsp"%>
	<s:if test="#session.userModel == null">
		<div class="div_login_no_user_main">数据为空，点击回到试题管理列表页面</div>
	</s:if>
	<s:else>
		<div></div>


		<div class="div_show_sub_detaile_header">
			<div class="sub_header">
				<span><strong>标题</strong></span><span class="sub_header_in"
					id="sub_header_title">java基础综合测试一</span>
			</div>
			<div class="sub_header">
				<span><strong>时间</strong></span><span class="sub_header_in"
					id="sub_header_time">2017年5月6日</span>
			</div>
			<div class="sub_header">
				<span><strong>总分</strong></span><span class="sub_header_in"
					id="sub_header_total_count">100分</span>
			</div>
			<div class="sub_header">
				<span><strong>题记</strong></span><span class="sub_header_in"
					id="sub_header_title_des">生命原是有所追寻，追寻中没有人能担保，一定是顺利安乐的吃点苦，也许是激励</span>
			</div>
		</div>

		<div class="div_header_and_selet_flag"></div>

		<div class="sub_add_content_div">
			<div class="sub_add_content_div_item">
				<div>
					<div class="sub_add_content_div_item_title">标题</div>
					<div class="sub_add_content_div_item_content">
						<textarea class="sub_add_content_text_item_content"
							id="sub_item_title" rows="10" cols="10"></textarea>
					</div>
				</div>
				<div>
					<div class="sub_add_content_div_item_title">A</div>
					<div class="sub_add_content_div_item_content">
						<textarea class="sub_add_content_text_item_content"
							id="sub_item_select_a" rows="10" cols="10"></textarea>
					</div>
				</div>
				<div>
					<div class="sub_add_content_div_item_title">B</div>
					<div class="sub_add_content_div_item_content">
						<textarea class="sub_add_content_text_item_content"
							id="sub_item_select_b" rows="10" cols="10"></textarea>
					</div>
				</div>
				<div>
					<div class="sub_add_content_div_item_title">C</div>
					<div class="sub_add_content_div_item_content">
						<textarea class="sub_add_content_text_item_content"
							id="sub_item_select_c" rows="10" cols="10"></textarea>
					</div>
				</div>
				<div>
					<div class="sub_add_content_div_item_title">D</div>
					<div class="sub_add_content_div_item_content">
						<textarea class="sub_add_content_text_item_content" rows="10"
							id="sub_item_select_d" cols="10"></textarea>
					</div>
				</div>
				<div>
					<div class="sub_add_content_div_item_title">正确选项</div>
					<div class="sub_add_content_div_item_content">
						<input type="text" class="sub_add_content_text_item_content"
							id="sub_item_select_s"></input>
					</div>
					<div>
						<div class="sub_add_content_div_item_title">本题分数</div>
						<div class="sub_add_content_div_item_content">
							<input type="text" class="sub_add_content_text_item_content"
								id="sub_item_select_count"></input>
						</div>
					</div>
					<div class="sub_add_content_div_item"></div>

					<div class="sub_add_content_div_item_add" onclick="addSubItem()">添加</div>
					
					
				</div>

			</div>
	</s:else>


	<script type="text/javascript">
		function loadingSubDetaile() {

			var uuid = getCookie("uuid");
			console.log("The uuid is: " + uuid);
			var url = "${pageContext.request.contextPath}/sub_getSubDetaile.action?time="
					+ new Date().getTime();
			$.post(url, {
				subUUid : encodeURI(uuid)
			}, function(data, textStatus) {
				if (textStatus == "success") {
					console.log("The textStatus is: " + textStatus);
					console.log("The data is: " + data);
					var code = data.code;
					var message = data.message;
					if (code == "1000") {
						var obj = data.content;
						if (obj != null) {
							console.log("The sub cookie is not  null ");
							var uSubIds = obj.uSubIds;
							var uSubImagUrl = obj.uSubImagUrl;
							var uSubItemList = obj.uSubItemList;
							var uSubStartTime = obj.uSubStartTime;
							var uSubUid = obj.uSubUid;
							var uSubName = obj.uSubName;
							var uSubPreface = obj.uSubPreface;

							console.log(" usubIds is " + uSubIds);
							console.log(" uSubUid is " + uSubUid);
							console.log(" uSubName is " + uSubName);
							console.log(" uSubPreface is " + uSubPreface);

							$('#sub_header_title').html(uSubName);

							$('#sub_header_time').html("时间");

							$('#sub_header_total_count').html("总分");

							$('#sub_header_title_des').html(uSubPreface);

						} else {
							console.log("The sub cookie is null ");
							$('#sub_header_title').html("数据 为空 ");
							$('#sub_header_time').html("数据 为空 ");

							$('#sub_header_total_count').html("数据 为空 ");

							$('#sub_header_title_des').html("数据 为空 ");
						}
					} else {
						console.log("The message is: " + message);
					}

				} else {
					console.log("The textStatus is: " + textStatus);
					alert("失败 ");
				}
			}, "json");

		}

		function addSubItem() {
			console.log("add sub item ");
			var url = "${pageContext.request.contextPath}/sub_addSubItem.action?time="
					+ new Date().getTime();
			var subUUid = getCookie("uuid");
			var $title =  $("#sub_item_title").val();
			if($title==null||$title == ""){
				alert("小题名称不可以为空");
				return false;
			}
			var $selects =  $("#sub_item_select_s").val();
			if($selects==null||$selects == ""){
				alert("小题正确选项不可为空");
				return false;
			}
			var $selectc =  $("#sub_item_select_count").val();
			if($selectc==null||$selectc == ""){
				alert("小题分数不可为空");
				return false;
			}
			$.post(
							url,
							{
								subUUID : encodeURI(subUUid),
								itemTitle : encodeURI($title),
								itemSelectA : encodeURI($("#sub_item_select_a")
										.val()),
								itemSelectB : encodeURI($("#sub_item_select_b")
										.val()),
								itemSelectC : encodeURI($("#sub_item_select_c")
										.val()),
								itemSelectD : encodeURI($("#sub_item_select_d")
										.val()),
								itemSelectS : encodeURI($("#sub_item_select_s")
										.val()),
								itemCount : encodeURI($(
										"#sub_item_select_count").val())
							},
							function(data, textStatus) {
								if (textStatus == "success") {
									var code = data.code;
									if (code == "1000") {
										alert("添加成功");
										var url = "${pageContext.request.contextPath}/index_subDetaileManager.action?time="
												+ new Date().getTime();
										window.location = url;
									} else {
										alert("添加失败" + data.message);
									}

								} else {
									alert("添加失败");
								}
							}, "json");

		}
		
	</script>


</body>
</html>